package gd.qaq.blue.locationleader.util.pathfinder;

import gd.qaq.blue.locationleader.LocationLeader;
import org.bukkit.Location;

import java.util.ArrayList;

public class PathUtils {
    public static ArrayList<Tile> createPath(Location start, Location target, int maxPathRange) {
        try {
            //create our pathfinder
            AStar pathFinder = new AStar(start, target, maxPathRange);
            //get the list of nodes to walk to as a Tile object
            ArrayList<Tile> route = pathFinder.iterate();
            //get the result of the path trace
            PathingResult res = pathFinder.getPathingResult();
            switch (res) {
                case SUCCESS:
                    LocationLeader.plugin.getLogger().info("success");
                    return route;
                case NO_PATH:
                    LocationLeader.plugin.getLogger().info("no_path");
                    break;
            }
        } catch (AStar.InvalidPathException e) {
            //InvalidPathException will be thrown if start or end block is air
            if (e.isEndNotSolid()) {
                LocationLeader.plugin.getLogger().info("End block is not walkable");
            }
            if (e.isStartNotSolid()) {
                LocationLeader.plugin.getLogger().info("Start block is not walkable");
            }
        }
        return null;
    }
}
